<?php

namespace app\api\model;

use think\Model;

class Category extends BaseModel
{

    protected $hidden = [
        'delete_time',
        'update_time',
        'topic_img_id'
    ];

    public function img()
    {
        return $this->belongsTo('Image', 'topic_img_id', 'id');
    }

    public function products()
    {
        return $this->hasMany('Product', 'category_id', 'id');
    }

    public static function getAllInfo()
    {
        $res = self::with('img')
                ->select();
        return $res;
    }

    public static function getOneDetail($id)
    {
        $res = self::with('products')
                ->find($id);
        return $res;
    }

}
